package org.reborn.engine.model

import mesh._
import org.reborn.model._
import org.reborn.model.bound._

import org.reborn.math._

import org.reborn.engine.enums.UpdateFrequency._

class Model extends Positioned with Oriented with Bounded{
//  var position:VectorF = null
//  var orientation:MatrixF = null
//  var bound:Bound = null
  var mesh:MutableMesh = null
  var registeredMeshId:Option[Int] = None
  var updateFreq:UpdateFrequency = Rarely
  
  def split(splitPlane:Plane3F,minDist:Float):(Option[Model],Option[Model]) = {
	def newModel(newMesh:MutableMesh):Option[Model] = {
	  if(newMesh.faces > 0){
		val model = new Model
		model.position = this.position;
		model.orientation = this.orientation;
		model.mesh = newMesh
		return Some(model)
	  }  
	  else
	 	return None
	}
	  
	val (negMesh,posMesh) = MeshUtil.partition(mesh, splitPlane, minDist)
	
	return (newModel(negMesh),newModel(posMesh))
  }
}